Skip to content

fix: Don't allocate extraneous memory in FastBufferReader#2265

Merged
simon-lemay-unity merged 3 commits intodevelopfrom
fix/allocator-none-allocation
Oct 19, 2022
Merged

fix: Don't allocate extraneous memory in FastBufferReader#2265
simon-lemay-unity merged 3 commits intodevelopfrom
fix/allocator-none-allocation

Conversation

@simon-lemay-unity
Copy link
Copy Markdown
Contributor

Creating a FastBufferReader with copyAllocator set to Allocator.None means not to allocate a copy of the buffer, and to instead directly use the one provided by the user. But in that situation the code would still allocate memory for the entire buffer. That memory would go unused.

Props to user Frolo on Discord for finding this issue.

Changelog

  • Fixed: Creating a FastBufferReader with Allocator.None will not result in extra memory being allocated for the buffer (since it's owned externally in that scenario).

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary.

@simon-lemay-unity simon-lemay-unity requested a review from a team as a code owner October 19, 2022 03:39
ReaderHandle* readerHandle = null;
if (copyAllocator == Allocator.None)
{
readerHandle = (ReaderHandle*)UnsafeUtility.Malloc(sizeof(ReaderHandle) + length, UnsafeUtility.AlignOf<byte>(), internalAllocator);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof! Good catch!

@simon-lemay-unity simon-lemay-unity enabled auto-merge (squash) October 19, 2022 19:02
@simon-lemay-unity simon-lemay-unity merged commit 443769e into develop Oct 19, 2022
@simon-lemay-unity simon-lemay-unity deleted the fix/allocator-none-allocation branch October 19, 2022 19:52
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…nologies#2265)

* fix: Don't allocate extraneous memory in FastBufferReader

* Add PR number to CHANGELOG entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants